<?php

    include './sql.php';

    // 获取前端发来的信息
    $user = $_REQUEST["user"];
    $password = $_REQUEST["password"];
    $email = $_REQUEST["email"];
    $name = $_REQUEST["name"];

    // 默认手机号处理
    $phonenumber = $user;

    // 获取数据库的信息
    $d = sqlQuery("SELECT * FROM user");

    // 循环判断是否已经存在
    for($a=0;$a<count($d);$a++){
        if($phomenumber==$d[$a]["phonenumber"]){
            $backData = array("code"=>1,"errMsg"=>"手机号已经被注册","sucMsg"=>"");
            die(json_encode($backData));
        }
        if($email==$d[$a]["email"]){
            $backData = array("code"=>1,"errMsg"=>"邮箱已经被注册","sucMsg"=>"");
            die(json_encode($backData));
        }
    }

    // 数据库插入语句
    $insql = "INSERT INTO user(user,password,name,email,phonenumber) VALUE('".$user."','".$password."','".$name."','".$email."','".$phonenumber."')";
    
    $res = sqlInsert($insql);

    if($res){
        die(json_encode($res));
    }

    // echo("注册成功")；

?>